function flow = swflow(A,C)
% calculate flow
% scripted by Sun Sibai
% 2015 May. 7
% A: adjacent matrix
%    A(j,k)=(j cites k)?1:0;
% C: clustering result
%    format: C(j,1)=paper;C(j,2)=cluster.
%C = sort(C,1);
 pmax = size(C,1)
 carr = unique(C(:,2))
 cmax = size(carr,1)
 Cabs = zeros(1,cmax(1,1));
 for itc=1:cmax
  Cabs(itc) = sum(C(:,2)==carr(itc));
  for itc1=1:cmax
   flow(itc,itc1) = sum(sum(A(find(C(:,2)-carr(itc)),find(C(:,2)-carr(itc1)))));
  end
 end
 Cdiv = Cabs'*Cabs;
 flow = flow./sqrt(Cdiv);
end
